package com.ck.print.demo.printbridge;

import lombok.Getter;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesReader {
    @Getter
    private final Properties properties;

    /**
     * 从resources目录加载properties文件
     * @param fileName properties文件名，如"config.properties"
     */
    public PropertiesReader(String fileName) {
        properties = new Properties();
        // 使用类加载器获取资源文件的输入流
        try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(fileName)) {
            if (inputStream == null) {
                throw new IllegalArgumentException("找不到资源文件: " + fileName);
            }
            // 加载properties文件内容
            properties.load(inputStream);
        } catch (IOException e) {
            throw new RuntimeException("加载properties文件失败: " + fileName, e);
        }
    }
}
